""" Test case for Task Class"""
import sys
import os
sys.path.append(os.path.abspath('..'))
import unittest
from service.task import Task
from service.task import TaskM
import Tix


class TestTask (unittest.TestCase):
    """ Test Case for Task and Task Manager"""
    def setUp (self):
        """ Create Task environment"""
        self.root=Tix.Tk()
        self.taskM = TaskM(self.root)
        self.taskM.config("../tasks/")
    def test_task (self):
        """ Test task object method"""
        print 'Test Task Object'
        task=self.taskM.load_task('Example')
        self.assertTrue(task.id >= 0)
        self.assertEqual(task.name, 'Example')
        self.assertTrue(task.view.show)
        self.assertTrue(task.view.Update)
        self.assertTrue(task.doc.run)
        task.doc.config("hello")
        self.taskM.remove_task(task.id)
        #print len(self.taskM.task_dict)

    def test_taskM (self):
        """Test task Manager method """
        print 'Test Task Manager'
        #Test all tasks from get_task_list() really exists
        for t in self.taskM.get_task_list():
            self.assertTrue(os.path.exists('../tasks/'+t+".py"))
        #Load 2 classes
        task_a=self.taskM.load_task('Example')
        task_b=self.taskM.load_task('Example')
        self.assertNotEqual(task_a.id,task_b.id)
        self.assertEqual(len(self.taskM.task_dict),2)
        self.taskM.run_task(task_a.id)
        self.taskM.remove_task(task_a.id)
        self.taskM.remove_task(task_b.id)

if __name__ == '__main__':
    unittest.main()

